<div ng-controller="userManageCtrl">
    <ol class="breadcrumb">
        <li><a href="javascript:void(0)">系统管理</a></li>
        <li>用户管理</li>
    </ol>
    <div class="content-container">
        <div class="query">
            <div class="row">
                <form>
                    <div class="col-lg-2">
                        <div class="input-group input-group-sm">
                            <input type="text" class="form-control" ng-model="conditions.name" placeholder="人员姓名">
                        </div>
                    </div>
                    <div class="col-lg-2">
                        <div class="input-group input-group-sm">
                            <input type="text" class="form-control" ng-model="conditions.username" placeholder="用户名">
                        </div>
                    </div>
                    <div class="col-lg-1">
                        <div class="input-group input-group-sm text-right">
                            <button class="btn btn-primary query-btn" ng-click="query()">查询</button>
                        </div>
                    </div>
                    <div class="col-lg-1">
                        <div class="input-group input-group-sm text-right">
                            <button class="btn btn-success query-btn" ng-click="add()">添加</button>
                        </div>
                    </div>
                    <div class="col-lg-1">
                        <div class="input-group input-group-sm text-right">
                            <button class="btn btn-default query-btn" ng-click="clearQuery()">清除</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
        <div class="row page-result" ng-show="data.length > 0">
            <div class="col-lg-6">
                符合您的查询结果共有
                <label class="text-danger" ng-bind="total"></label>条
            </div>
            <div class="col-lg-6">
                <div class="pagination-size">
                    <select ng-change="changePageSize()" class="form-control input-sm" ng-options="option.name for option in page_size_arr track by option.value" ng-model="page_size">
                    </select>
                </div>
                <ul uib-pagination total-items="total" ng-model="conditions.page" max-size="5" class="pagination-sm pull-right" boundary-link-numbers="true" previous-text="上一页" next-text="下一页" items-per-page="conditions.rows" ng-change="query()"></ul>
            </div>
        </div>
        <div class="datagrid">
            <table class="table table-bordered" ng-show="data.length > 0">
                <tr>
                    <th style="width:5%;">序号</th>
                    <th style="width:15%;">人员姓名</th>
                    <th style="width:15%;">用户名</th>
                    <th style="width:10%;">所属上级</th>
                    <th style="width:10%;">所属角色</th>
                    <th style="width:10%;">所属城市</th>
                    <!-- <th style="width:10%;">状态</th> -->
                    <th style="width:25%;">操作</th>
                </tr>
                <tr ng-repeat="user in data" ng-click="selectRow(user)" ng-class="{'bg-info' : user.selected}" >
                    <td>{{$index+1+(conditions.page-1)*conditions.rows}}</td>
                    <td>{{user.name}}</td>
                    <td>{{user.username}}</td>
                    <td>{{user.adminName}}</td>
                    <td>{{user.roleName}}</td>
                    <td>{{user.cityName}}</td>
                    <!-- <td>{{user.status}}</td> -->
                    <td>
                        <button class="btn btn-success btn-sm" ng-click="update(user)"><span class="glyphicon glyphicon-pencil top-2 right-2"></span>修改</button>
                        <button class="btn btn-danger btn-sm" ng-click="delete(user.id)"><span class="glyphicon glyphicon-remove top-2 right-2"></span>删除</button>
                        <button class="btn btn-info btn-sm" ng-click="passwordUpdate(user.id)"><span class="glyphicon glyphicon-off top-2 right-2"></span>重置密码</button>
                        <button class="btn btn-primary btn-sm" ng-click="detail(user)"><span class="glyphicon glyphicon-glass top-2 right-2"></span>详情</button>
                    </td>
                </tr>
            </table>
            <div ng-show="data.length == 0" class="alert alert-warning">
                <span class="glyphicon glyphicon-info-sign"></span>&nbsp;查无相关数据，请重新查询！
            </div>
        </div>
    </div>
    <div alert title="alert.title" content="alert.content" open="alert.open"></div>
</div>
<!-- end controller -->
<!-- 新增窗口 -->
<script type="text/ng-template" id="add.html">
    <div class="modal-header">
         <button type="button" class="close" ng-click="cancel()"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
        <h3 class="modal-title" id="modal-title">用户管理信息{{title}}</h3>
    </div>
    <form name="add_form" novalidate >
        <div class="modal-body" id="modal-body">
            <div class="info_bd">
                <div class="sub_title">基本信息</div>
                <div class="form-horizontal">
                    <div class="form-group">
                        <div class="col-md-6 m-t-1">
                            <span class="col-md-4 remove-padding control-label">
                                <em class="text-require">*</em>人员姓名：
                            </span>
                            <div class="col-md-8">
                                <input type="text" name="name" class="form-control" ng-model="user.name" placeholder="人员姓名" required id="add_name">
                                    <div ng-show="add_form.name.$dirty && add_form.name.$invalid" class="invalid">
                                        <span ng-show="add_form.name.$error.required">请填写人员姓名</span>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6 m-t-1">
                            <span class="col-md-4 remove-padding control-label">
                                <em class="text-require">*</em>用户名：
                            </span>
                            <div class="col-md-8">
                                <input type="text" name="username" class="form-control" ng-model="user.username" placeholder="用户名" required>
                                    <div ng-show="add_form.username.$dirty && add_form.username.$invalid" class="invalid">
                                        <span ng-show="add_form.username.$error.required">请填写用户名</span>
                                    </div>
                            </div>
                        </div>
                        <div class="col-md-6 m-t-1">
                            <span class="col-md-4 remove-padding control-label">
                                <em class="text-require">*</em>用户密码：
                            </span>
                            <div class="col-md-8">
                                <input type="password" name="password" class="form-control" ng-model="user.password" placeholder="用户密码" required>
                                    <div ng-show="add_form.password.$dirty && add_form.password.$invalid" class="invalid">
                                        <span ng-show="add_form.password.$error.required">请填写用户密码</span>
                                    </div>
                            </div>
                        </div>
                        <div class="col-md-6 m-t-1">
                            <span class="col-md-4 remove-padding control-label">
                                <em class="text-require">*</em>重复密码：
                            </span>
                            <div class="col-md-8">
                                <input type="password" class="form-control" ng-model="user.cpw" name="cpw" placeholder="重复密码" required>
                                    <div ng-show="add_form.cpw.$dirty && add_form.cpw.$invalid" class="invalid">
                                        <span ng-show="add_form.cpw.$error.required">请填写重复密码</span>
                                    </div>
                                    <div ng-show="add_form.cpw.$dirty && user.cpw!=user.password" class="invalid">
                                        <span>密码不一致</span>
                                    </div>
                            </div>
                        </div>
                        <div class="col-md-6 m-t-1">
                            <span class="col-md-4 remove-padding control-label">
                                所属上级：
                            </span>
                            <div class="col-md-8" form-search my-list="admins" select-value="user.select_admin" select-id="user.adminId" key="name" placeholder="请选择所属上级">
                            </div>
                        </div>
                        <div class="col-md-6 m-t-1">
                            <span class="col-md-4 remove-padding control-label">
                                <em class="text-require">*</em>所属城市：
                            </span>
                            <div class="col-md-8">
                                <select class="form-control" ng-model="user.cityId" name="cityId" required>
                                    <option value="">请选择</option>
                                    <option value="{{key.value}}" ng-repeat="key in citys">{{key.keyword}}</option>
                            </select>
                            <div ng-show="add_form.cityId.$dirty && add_form.cityId.$invalid" class="invalid">请选择所属城市</div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="sub_title">负责门店</div>
                <div class="form-group user-role clearfix">
                    <div class="col-sm-3" ng-repeat="store in store_list">
                        <div class="select-box">
                            <span ng-class="{'unselect': !store.checked, 'select': store.checked}" ng-click="toggleStore(store)"></span>
                        </div>
                        {{store.name}}
                    </div>
                </div>
                <div class="sub_title">角色权限</div>
                <div class="form-group user-role clearfix">
                    <div class="col-sm-3" ng-repeat="role in role_list">
                        <div class="select-box">
                            <span ng-class="{'unselect': !role.checked, 'select': role.checked}" ng-click="toggleRole(role)"></span>
                        </div>
                        {{role.name}}
                    </div>
                </div>
            </div>
            
        </div>
        <div class="modal-footer">
            <button ng-disabled="add_form.$invalid || user.cpw!=user.password || not_role || not_store" class="btn btn-primary" type="button" ng-click="ok()">确定</button>
            <button class="btn btn-default" type="button" ng-click="cancel()">取消</button>
        </div>
    </form>
</script>
<!-- 修改窗口 -->
<script type="text/ng-template" id="update.html">
    <div class="modal-header">
         <button type="button" class="close" ng-click="cancel()"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
        <h3 class="modal-title" id="modal-title">用户管理信息{{title}}</h3>
    </div>
    <form name="add_form" novalidate >
        <div class="modal-body" id="modal-body">
            <div class="info_bd">
                <div class="sub_title">基本信息</div>
                <div class="form-horizontal">
                    <div class="form-group">
                        <div class="col-md-6 m-t-1">
                            <span class="col-md-4 remove-padding control-label">
                                <em class="text-require">*</em>人员姓名：
                            </span>
                            <div class="col-md-8">
                                <input type="text" name="name" class="form-control" ng-model="user.name" placeholder="人员姓名" required id="add_name">
                                    <div ng-show="add_form.name.$dirty && add_form.name.$invalid" class="invalid">
                                        <span ng-show="add_form.name.$error.required">请填写人员姓名</span>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6 m-t-1">
                            <span class="col-md-4 remove-padding control-label">
                                <em class="text-require">*</em>用户名：
                            </span>
                            <div class="col-md-8">
                                <input type="text" name="username" class="form-control" ng-model="user.username" placeholder="用户名" required>
                                    <div ng-show="add_form.username.$dirty && add_form.username.$invalid" class="invalid">
                                        <span ng-show="add_form.username.$error.required">请填写用户名</span>
                                    </div>
                            </div>
                        </div>
                        <div class="col-md-6 m-t-1">
                            <span class="col-md-4 remove-padding control-label">
                                所属上级：
                            </span>
                            <div class="col-md-8" form-search my-list="admins" select-value="user.select_admin" select-id="user.adminId" key="name" placeholder="请选择所属上级">
                            </div>
                        </div>
                        <div class="col-md-6 m-t-1">
                            <span class="col-md-4 remove-padding control-label">
                                <em class="text-require">*</em>所属城市：
                            </span>
                            <div class="col-md-8">
                                <select class="form-control" ng-model="user.cityId" name="cityId" required>
                                    <option value="">请选择</option>
                                    <option value="{{key.value}}" ng-repeat="key in citys">{{key.keyword}}</option>
                            </select>
                            <div ng-show="add_form.cityId.$dirty && add_form.cityId.$invalid" class="invalid">请选择所属城市</div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="sub_title">负责门店</div>
                <div class="form-group user-role clearfix">
                    <div class="col-sm-3" ng-repeat="store in store_list">
                        <div class="select-box">
                            <span ng-class="{'unselect': !store.checked, 'select': store.checked}" ng-click="toggleStore(store)"></span>
                        </div>
                        {{store.name}}
                    </div>
                </div>
                <div class="sub_title">角色权限</div>
                <div class="form-group user-role clearfix">
                    <div class="col-sm-3" ng-repeat="role in role_list">
                        <div class="select-box">
                            <span ng-class="{'unselect': !role.checked, 'select': role.checked}" ng-click="toggleRole(role)"></span>
                        </div>
                        {{role.name}}
                    </div>
                </div>
            </div>
            
        </div>
        <div class="modal-footer">
            <button ng-disabled="add_form.$invalid || not_role || not_store" class="btn btn-primary" type="button" ng-click="ok()">确定</button>
            <button class="btn btn-default" type="button" ng-click="cancel()">取消</button>
        </div>
    </form>
</script>
<!-- accordion heading模板 -->
<script type="text/ng-template" id="group-template.html">
    <div class="panel panel-default">
        <div class="panel-heading" ng-click="toggleOpen()">
            <h4 class="panel-title" >
          <a href tabindex="0" class="accordion-toggle" uib-accordion-transclude="heading">
            <span uib-accordion-header>
              {{heading}}
            </span>
          </a>
        </h4>
        </div>
        <div class="panel-collapse collapse" uib-collapse="!isOpen">
            <div class="panel-body" ng-transclude>
                
            </div>
        </div>
    </div>
</script>
<script type="text/ng-template" id="detail.html">
    <div class="modal-header">
        <button type="button" class="close" ng-click="cancel()"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
        <h3 class="modal-title" id="modal-title">客户详细信息</h3>
    </div>
    <div class="modal-body" id="modal-body">
        <table class="table table-bordered">
            <tr>
                <td><b>人员姓名：</b></td>
                <td>{{user.name}}</td>
                <td><b>用户名：</b></td>
                <td>{{user.username}}</td>
                
            </tr>
            <tr>
                <td><b>所属角色：</b></td>
                <td>{{user.roleName}}</td>
                <td><b>所属上级：</b></td>
                <td>{{user.adminName}}</td>
            </tr>
            <tr>
                <td><b>所属城市：</b></td>
                <td colspan="3">{{user.cityName}}</td>
            </tr>
            <tr>
                <td><b>负责门店：</b></td>
                <td colspan="3">{{user.companyNames}}</td>
            </tr>
        </table>
    </div>
    <div class="modal-footer">
        <button class="btn btn-default" type="button" ng-click="cancel()">取消</button>
    </div>
</script>